from datetime import  datetime
from django.db import models
from organization.models import CourseOrg, TeacherModel

class CourseModel(models.Model):
    """课程模型"""
    degree_type = (('zj', '初级'), ('zj', '中级'), ('gj', '高级'))

    course_org = models.ForeignKey(CourseOrg, on_delete=models.CASCADE, verbose_name='课程机构')
    teacher = models.ForeignKey(TeacherModel, on_delete=models.CASCADE, verbose_name='教师')
    teacher_tell = models.CharField(verbose_name='老师告诉你', max_length=200, blank=True, null=True, default='好好学，必成大器')
    name = models.CharField(verbose_name='课程名', max_length=50)
    tag = models.CharField(verbose_name='课程标签', max_length=100, default='', blank=True, null=True)
    category = models.CharField(verbose_name='课程类别', max_length=200, default='', blank=True, null=True)
    you_need_know = models.CharField(verbose_name='课程须知', max_length=200, default='', blank=True, null=True)
    desc = models.TextField(verbose_name='课程描述', default='', blank=True, null=True)
    detail = models.TextField(verbose_name='课程描述', default='', blank=True, null=True)
    degree = models.CharField(verbose_name='课程难度', max_length=10, choices=degree_type, default='zj')
    image = models.ImageField(upload_to='course/%Y/%m', verbose_name='封面图')
    is_banner = models.BooleanField(verbose_name='是否轮播', default=False)
    learn_times = models.IntegerField(verbose_name='学习时长', default=0)
    students = models.IntegerField(verbose_name='学习人数', default=0)
    fav_nums = models.IntegerField(verbose_name='收藏人数', default=0)
    click_nums = models.IntegerField(verbose_name='点击数', default=0)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '课程'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class LessonModel(models.Model):
    """章节"""
    course = models.ForeignKey(CourseModel, on_delete=models.CASCADE, verbose_name='课程')
    name = models.CharField(verbose_name='章节名', max_length=50, default='')
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '章节'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class VideoModel(models.Model):
    """视频模型"""
    lesson = models.ForeignKey(LessonModel, on_delete=models.CASCADE, verbose_name='章节')
    name = models.CharField(verbose_name='视频名称', max_length=100)
    url = models.CharField(verbose_name='视频链接', max_length=200, blank=True, null=True, default='https://www.baidu.com')
    learn_times = models.IntegerField(verbose_name='学习时长', default=0)
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '视频'
        verbose_name_plural = verbose_name


class CourseResourceModel(models.Model):
    """课程资源模型"""
    course = models.ForeignKey(CourseModel, on_delete=models.CASCADE, verbose_name='课程')
    name = models.CharField(verbose_name='资源名称', max_length=100)
    download = models.FileField(upload_to='course/resource/%Y/%m', verbose_name='资源文件')
    add_time = models.DateTimeField(verbose_name='添加时间', default=datetime.now())

    class Meta:
        verbose_name = '课程资源'
        verbose_name_plural = verbose_name